<?php
class ProfileController extends AppController {

	var $name = 'Profile';

	function beforeFilter() {
		parent::beforeFilter();
	}

	function index() {
		$data = false;
		$u = $this->Auth->user();

		if (!empty($u)) {
			$uid = $u['User']['id'];
			if (isset($this->data)) {
#pr ($this->data);
				if (isset($this->data['Profile'])) {
					$pData = $this->data['Profile'];

					$this->Profile->id = $this->Profile->getProfileID($uid);
					$pData['user_id'] = $uid;

					$birth = $pData['birthday'];
					$pData['birthday'] = $birth['year'] .'-'. $birth['month'] .'-'. $birth['day'];


					$this->Profile->save($pData);
				}

			}
			if (!is_array($this->data)) { $this->data = array(); }
			$this->data = array_merge($this->Profile->getData($uid), $this->data);

			//$this->loadModel('City');
			//$data['cities'] = $this->City->find('all');
		}

		if ($data) {
			$this->set($data);
		}
	}
}
?>
